home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Filling Shapes with a Gradient Brush / Creating a Linear Gradient / Customizing Linear Gradients / GDITEST61.dpr
Encoding:
Text File  |  2003-10-15  |  2.6 KB  |  102 lines

  1. program GDITEST61;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   linGrBrush: TGPLinearGradientBrush;
  15. const
  16.   relativeIntensities : array[0..2] of Single = (0.0, 0.5, 1.0);
  17.   relativePositions : array[0..2] of Single = (0.0, 0.2, 1.0);
  18. begin
  19.   graphics := TGPGraphics.Create(DC);
  20.  
  21.   linGrBrush := TGPLinearGradientBrush.Create(
  22.     MakePoint(0, 10),
  23.     MakePoint(200, 10),
  24.     MakeColor(255, 0, 0, 0),   // opaque red
  25.     MakeColor(255, 255, 0, 0));  // opaque blue
  26.  
  27.   linGrBrush.SetBlend(@relativeIntensities, @relativePositions, 3);
  28.  
  29.   graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);
  30.   graphics.FillRectangle(linGrBrush, 0, 155, 500, 30);
  31.  
  32.   linGrBrush.Free;
  33.   graphics.Free;
  34. end;
  35.  
  36.  
  37. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  38. var
  39.   Handle: HDC;
  40.   ps: PAINTSTRUCT;
  41. begin
  42.   case message of
  43.     WM_PAINT:
  44.       begin
  45.         Handle := BeginPaint(Wnd, ps);
  46.         OnPaint(Handle);
  47.         EndPaint(Wnd, ps);
  48.         result := 0;
  49.       end;
  50.  
  51.     WM_DESTROY:
  52.       begin
  53.         PostQuitMessage(0);
  54.         result := 0;
  55.       end;
  56.  
  57.    else
  58.       result := DefWindowProc(Wnd, message, wParam, lParam);
  59.    end;
  60. end;
  61.  
  62. var
  63.   hWnd     : THandle;
  64.   Msg      : TMsg;
  65.   wndClass : TWndClass;
  66. begin
  67.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  68.    wndClass.lpfnWndProc    := @WndProc;
  69.    wndClass.cbClsExtra     := 0;
  70.    wndClass.cbWndExtra     := 0;
  71.    wndClass.hInstance      := hInstance;
  72.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  73.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  74.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  75.    wndClass.lpszMenuName   := nil;
  76.    wndClass.lpszClassName  := 'GettingStarted';
  77.  
  78.    RegisterClass(wndClass);
  79.  
  80.    hWnd := CreateWindow(
  81.       'GettingStarted',       // window class name
  82.       'Customizing Linear Gradients',       // window caption
  83.       WS_OVERLAPPEDWINDOW,    // window style
  84.       Integer(CW_USEDEFAULT), // initial x position
  85.       Integer(CW_USEDEFAULT), // initial y position
  86.       Integer(CW_USEDEFAULT), // initial x size
  87.       Integer(CW_USEDEFAULT), // initial y size
  88.       0,                      // parent window handle
  89.       0,                      // window menu handle
  90.       hInstance,              // program instance handle
  91.       nil);                   // creation parameters
  92.  
  93.    ShowWindow(hWnd, SW_SHOW);
  94.    UpdateWindow(hWnd);
  95.  
  96.    while(GetMessage(msg, 0, 0, 0)) do
  97.    begin
  98.       TranslateMessage(msg);
  99.       DispatchMessage(msg);
  100.    end;
  101. end.
  102.